package View;
import java.awt.Color;
import java.awt.Dimension;
import java.awt.Font;
import java.awt.Graphics;
import javax.swing.JPanel;

public class CompasPanel extends JPanel{

	private double x;
	private double y;
	private Font font;
	
	public CompasPanel()
	{
		font = new Font("Serif", Font.BOLD, 14);
		setPreferredSize(new Dimension(600, 100));
		setBackground(Color.GREEN.darker().darker().darker().darker());
	}
	public void setXY(double xx, double yy)
	{
		x = xx;
		y = yy;
	}
	public void paintComponent(Graphics g)
	{
		super.paintComponent(g);
		g.setColor(Color.BLACK);
		g.drawOval(0, 0, 100, 100);
		g.fillOval(0, 0, 100, 100);
	
		double a = Math.sqrt(x*x + y*y);
		
		int compasx =  (int)(x/a * 35);
		int compasy = (int)(y/a * 35);
		
		g.setColor(Color.GREEN);
		g.drawLine(50-compasx, 50-compasy,50+compasx, 50+compasy);
		g.setFont(font);
		g.drawString("N", 47, 15);
		g.drawString("Z", 47, 95);
		g.drawString("O", 87, 55);
		g.drawString("W", 5 , 55);
		g.fillOval(50+compasx-5, 50+compasy-5, 10, 10);
		g.drawString("Snelheid:"+ a*100 + " kmph", 110,20);
	}
}
